package com.bitcola.security.activity.biz;

import com.bitcola.security.activity.mapper.BalanceChangeLogMapper;
import com.bitcola.security.activity.mapper.ColaUserBalanceMapper;
import com.bitcola.security.activity.mapper.LockPositionMapper;
import com.bitcola.security.activity.mapper.SignUpMapper;
import com.bitcola.security.activity.entity.SignUp;
import com.bitcola.security.auth.common.util.EncoderUtil;
import com.bitcola.security.common.biz.BaseBiz;
import com.bitcola.security.common.constant.BalanceTypeConstants;
import com.bitcola.security.common.constant.FinancialConstant;
import com.bitcola.security.common.util.Snowflake;
import com.bitcola.entity.BalanceChange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;

/**
 *  @author wx
 * @create 2018-11-29 12:33
 **/
@Service
public class SignUpBiz extends BaseBiz<SignUpMapper, SignUp> {

    public static final BigDecimal NEW_USER = new BigDecimal(20);
    public static final BigDecimal INVITER = new BigDecimal(10);
    public static final BigDecimal ALCT_REWARD = new BigDecimal(15);
    LockPositionMapper lockPositionMapper;
    Snowflake snowflake=new Snowflake(4,1);
    @Autowired
    ColaUserBalanceMapper colaUserBalanceMapper;

    @Autowired
    BalanceChangeLogMapper balanceChangeLogMapper;
    @Transactional(isolation = Isolation.READ_COMMITTED)
    public boolean reward(String userId) {

        BigDecimal amount= BigDecimal.valueOf(10);
        String coinCode="USDT";
         colaUserBalanceMapper.changeUserBanlance(userId,coinCode,BigDecimal.ZERO,BigDecimal.ZERO,amount,BigDecimal.ZERO,BigDecimal.ZERO, BigDecimal.ZERO,EncoderUtil.BALANCE_KEY);
        BalanceChange change=new BalanceChange();
        change.setId(snowflake.nextIdStr());
        change.setSource(BalanceTypeConstants.prize_balance_frozen);
        change.setAmount(amount);
        change.setCreateTime(new Date());
        change.setType(FinancialConstant.ACTIVITY_REWARD);
        change.setUserId(userId);
        balanceChangeLogMapper.insert(change);
        return true;



    }



}
